﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Petaframe.Configuration
{
    public class LoggingConfigReader : ConfigReaderBase
    {
        public LoggingConfigReader()
        {

        }
        public LoggingConfigReader(string pysicalConfigFilePath)
            : base(pysicalConfigFilePath)
        {
            
        }
        
        public override IDictionary<string, IEnumerable<XElement>> ReadConfig()
        {
            var logging = xdoc.Root.Element("Petaframe.Logging");
            if (logging != null)
            {
                var mailloggers = new List<XElement>(logging.Descendants("emailLogger"));

                if (mailloggers.Count() > 0)
                {
                    configElements.Add("emailLoggers", mailloggers);
                }

                var eventLogLoggers = new List<XElement>(logging.Descendants("eventLogLogger"));

                if (eventLogLoggers.Count() > 0)
                {
                    configElements.Add("eventLogLoggers", eventLogLoggers);
                }

                var fileLoggers = new List<XElement>(logging.Descendants("fileLogger"));

                if (fileLoggers.Count() > 0)
                {
                    configElements.Add("fileLoggers", eventLogLoggers);
                }

                var rollingDateFileLoggers = new List<XElement>(logging.Descendants("rollingDateFileLogger"));

                if (rollingDateFileLoggers.Count() > 0)
                {
                    configElements.Add("rollingDateFileLoggers", rollingDateFileLoggers);
                }

                var rollingSizeFileLoggers = new List<XElement>(logging.Descendants("rollingSizeFileLogger"));

                if (rollingSizeFileLoggers.Count() > 0)
                {
                    configElements.Add("rollingSizeFileLoggers", rollingSizeFileLoggers);
                }

                var consoleLoggers = new List<XElement>(logging.Descendants("consoleLogger"));

                if (consoleLoggers.Count() > 0)
                {
                    configElements.Add("consoleLoggers", consoleLoggers);
                }

            }



            return configElements;
        }
    }
}
